package com.androidhuman.example.Widgets3;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;

public class Widgets3Activity extends Activity implements OnClickListener, 
			RatingBar.OnRatingBarChangeListener, SeekBar.OnSeekBarChangeListener{
    private ProgressBar progBar;
    private SeekBar seekBar;
    private Button toggleIndeterminate;
    private RatingBar ratingBar;
    private Button increasePrmProgress;
    private Button decreasePrmProgress;
    private Button increaseSecProgress;
    private Button decreaseSecProgress;
    private TextView seekBarText;
    private TextView ratingBarText;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        progBar = (ProgressBar)findViewById(R.id.progressHorizontal);
        seekBar = (SeekBar)findViewById(R.id.seekBar);
        toggleIndeterminate = (Button)findViewById(R.id.toggleIndeterminate);
        ratingBar = (RatingBar)findViewById(R.id.ratingBar);
        increasePrmProgress = (Button)findViewById(R.id.increasePrimaryProgress);
        decreasePrmProgress = (Button)findViewById(R.id.decreasePrimaryProgress);
        increaseSecProgress = (Button)findViewById(R.id.increaseSecondaryProgress);
        decreaseSecProgress = (Button)findViewById(R.id.decreaseSecondaryProgress);
        seekBarText = (TextView)findViewById(R.id.seekBarText);
        ratingBarText = (TextView)findViewById(R.id.ratingText);
        
        increasePrmProgress.setOnClickListener(this);
        decreasePrmProgress.setOnClickListener(this);
        increaseSecProgress.setOnClickListener(this);
        decreaseSecProgress.setOnClickListener(this);
        toggleIndeterminate.setOnClickListener(this);
        seekBar.setOnSeekBarChangeListener(this);
        ratingBar.setOnRatingBarChangeListener(this);
        
    }

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.toggleIndeterminate:
			progBar.setIndeterminate(!progBar.isIndeterminate());
			break;
		
		case R.id.increasePrimaryProgress:
			progBar.incrementProgressBy(1);
			break;
			
		case R.id.decreasePrimaryProgress:
			progBar.incrementProgressBy(-1);
			break;
			
		case R.id.increaseSecondaryProgress:
			progBar.incrementSecondaryProgressBy(1);
			break;
			
		case R.id.decreaseSecondaryProgress:
			progBar.incrementSecondaryProgressBy(-1);
			break;
		}
		
	}

	@Override
	public void onRatingChanged(RatingBar ratingBar, float rating,
			boolean fromUser) {
		ratingBarText.setText("Rating : "+rating+"/5.0");
		
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		seekBarText.setText("SeekBar at : "+progress);
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
				
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
				
	}
}